/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Trp_cursoDAOImpl implements orm.dao.Trp_cursoDAO {
	public Trp_curso loadTrp_cursoByORMID(int cu_id) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_cursoByORMID(session, cu_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_curso getTrp_cursoByORMID(int cu_id) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return getTrp_cursoByORMID(session, cu_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_curso loadTrp_cursoByORMID(int cu_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_cursoByORMID(session, cu_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_curso getTrp_cursoByORMID(int cu_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return getTrp_cursoByORMID(session, cu_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_curso loadTrp_cursoByORMID(PersistentSession session, int cu_id) throws PersistentException {
		try {
			return (Trp_curso) session.load(orm.Trp_curso.class, new Integer(cu_id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_curso getTrp_cursoByORMID(PersistentSession session, int cu_id) throws PersistentException {
		try {
			return (Trp_curso) session.get(orm.Trp_curso.class, new Integer(cu_id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_curso loadTrp_cursoByORMID(PersistentSession session, int cu_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Trp_curso) session.load(orm.Trp_curso.class, new Integer(cu_id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_curso getTrp_cursoByORMID(PersistentSession session, int cu_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Trp_curso) session.get(orm.Trp_curso.class, new Integer(cu_id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_curso[] listTrp_cursoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return listTrp_cursoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_curso[] listTrp_cursoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return listTrp_cursoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_curso[] listTrp_cursoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_curso as Trp_curso");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Trp_curso[]) list.toArray(new Trp_curso[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_curso[] listTrp_cursoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_curso as Trp_curso");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Trp_curso[]) list.toArray(new Trp_curso[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_curso loadTrp_cursoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_cursoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_curso loadTrp_cursoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_cursoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_curso loadTrp_cursoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Trp_curso[] trp_cursos = listTrp_cursoByQuery(session, condition, orderBy);
		if (trp_cursos != null && trp_cursos.length > 0)
			return trp_cursos[0];
		else
			return null;
	}
	
	public Trp_curso loadTrp_cursoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Trp_curso[] trp_cursos = listTrp_cursoByQuery(session, condition, orderBy, lockMode);
		if (trp_cursos != null && trp_cursos.length > 0)
			return trp_cursos[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTrp_cursoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return iterateTrp_cursoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_cursoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return iterateTrp_cursoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_cursoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_curso as Trp_curso");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_cursoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_curso as Trp_curso");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_curso createTrp_curso() {
		return new orm.Trp_curso();
	}
	
	public boolean save(orm.Trp_curso trp_curso) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().saveObject(trp_curso);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Trp_curso trp_curso) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().deleteObject(trp_curso);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Trp_curso trp_curso)throws PersistentException {
		try {
			if(trp_curso.getNivel_id_nivel() != null) {
				trp_curso.getNivel_id_nivel().trp_curso.remove(trp_curso);
			}
			
			if(trp_curso.getColegio() != null) {
				trp_curso.getColegio().trp_curso.remove(trp_curso);
			}
			
			orm.Trp_alumno[] lTrp_alumno1s = trp_curso.trp_alumno1.toArray();
			for(int i = 0; i < lTrp_alumno1s.length; i++) {
				lTrp_alumno1s[i].setCurso(null);
			}
			return delete(trp_curso);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Trp_curso trp_curso, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(trp_curso.getNivel_id_nivel() != null) {
				trp_curso.getNivel_id_nivel().trp_curso.remove(trp_curso);
			}
			
			if(trp_curso.getColegio() != null) {
				trp_curso.getColegio().trp_curso.remove(trp_curso);
			}
			
			orm.Trp_alumno[] lTrp_alumno1s = trp_curso.trp_alumno1.toArray();
			for(int i = 0; i < lTrp_alumno1s.length; i++) {
				lTrp_alumno1s[i].setCurso(null);
			}
			try {
				session.delete(trp_curso);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Trp_curso trp_curso) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().getSession().refresh(trp_curso);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Trp_curso trp_curso) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().getSession().evict(trp_curso);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_curso loadTrp_cursoByCriteria(Trp_cursoCriteria trp_cursoCriteria) {
		Trp_curso[] trp_cursos = listTrp_cursoByCriteria(trp_cursoCriteria);
		if(trp_cursos == null || trp_cursos.length == 0) {
			return null;
		}
		return trp_cursos[0];
	}
	
	public Trp_curso[] listTrp_cursoByCriteria(Trp_cursoCriteria trp_cursoCriteria) {
		return trp_cursoCriteria.listTrp_curso();
	}
}
